# 对自己的内容进行布谷鸟hash，并且存储结果到本地文件中
import os
import subprocess
from conf import conf

def work():
    base_dir = os.path.dirname(os.path.abspath(__file__))+"/../../"
    input_file = base_dir + "/data/client/a.bin"
    output_file = base_dir + "/data/client/cuckoo.bin"
    position_file = base_dir + "/data/client/position.bin"
    result = subprocess.run([base_dir + "/bin/cuckoo_cli.exe", input_file, output_file,position_file], capture_output=True,
                   text=True)

    # 返回码（exit code，0表示成功）：
    print("return code:", result.returncode)
    # 标准输出（子程序的输出）：
    print("stdout:", result.stdout.strip())
    # 标准错误（如果有错误信息）：
    print("stderr:", result.stderr.strip())

    if result.returncode == 0:
        conf.set_config("bucket_num", int(result.stdout.strip()))
        return True
    return False
if __name__ == '__main__':
    work()